require "ActionUtil"
require "NodeManager"
require "MainScene"
require "WarScene"
require "ZhanDouScene"
require "UserData"
require "NetworkRequest"
-- for CCLuaEngine traceback
function __G__TRACKBACK__(msg)
    print("----------------------------------------")
    print("LUA ERROR: " .. tostring(msg) .. "\n")
    print(debug.traceback())
    print("----------------------------------------")
end

local function main()
    -- avoid memory leak
    collectgarbage("setpause", 100)
    collectgarbage("setstepmul", 5000)

    local visibleSize = CCDirector:sharedDirector():getVisibleSize()
    local origin = CCDirector:sharedDirector():getVisibleOrigin()
  
    local str = cjson.encode({[1]=12,[2]=22})
    print(str)
    --local path=CCFileUtils:sharedFileUtils():fullPathFromRelativePath("tmp.json")
    --local txt=CCString:createWithContentsOfFile(path):getCString()
    --cjson.decode(txt)  
    --  setTouchEnabledAll(nil, true)
    UserData.init();
    --CCHttpClient:request("http://user.alonew.com/login/serverMap?group=2", "onHttpCompleted")
    --CCHttpClient:request("http://app18894.qqgameapp.com/game/user/info.php?openid=0000000000000000000000005B168614&openkey=A76D7BCF866939B8121DDE9B5C9E9CD9&pf=pengyou&pfkey=c6c150ba2bd86315549585da7c3dbb49&qz_ver=6&appcanvas=1&via=PY.TOPBAR.SEARCH", "onHttpCompleted", "")
    --NetworkRequest.getBattlePVE(1, 1)
    --NetworkRequest.login()
    --NetworkRequest.getUserInfo()
    --mainScene = CCBReader:load("MainSceneHD.ccbi")
    --local sceneGame = CCScene:create()
    --sceneGame:addChild(MainScene.getNode())
    --setTouchEnabledAll(mainScene, false)
    --sceneGame:addChild(CCBReader:load("test.ccbi"))
    --sceneGame:addChild(YuanZhenScene.getNode())
    --sceneGame:addChild(GuanKaScene.getNode())
    print(os.date())
    CCDirector:sharedDirector():runWithScene(BeginScene.getScene())
    --FightData.load() 
    --CCDirector:sharedDirector():runWithScene(WarScene.getScene())
    --CCDirector:sharedDirector():runWithScene(ZhanDouScene.getScene())
    --CCDirector:sharedDirector():runWithScene(ZhuangBeiScene.getScene())
    --CCDirector:sharedDirector():runWithScene(XunLianYingScene.getScene())
    --CCDirector:sharedDirector():runWithScene(RenWuScene.getScene())
    --CCDirector:sharedDirector():runWithScene(ZhuangBeiLayer3.getScene())
    --CCDirector:sharedDirector():runWithScene(JunXiaoScene.getScene())
    --CCDirector:sharedDirector():runWithScene(ZBQHLayer:getScene())
    --CCDirector:sharedDirector():runWithScene(JLRMLayer:getScene())

    --[[
    --local b=CCButton:createWithFileName("onTestButton","UI8.png","UI8.png","UI8.png")  
    local b=CCButton:createWithFileName("onTestButton","build1.png","build1.png","build1.png")  
    print("button", b)
    b:setPosition(200,200)    
    mainScene:addChild(b)    
    --b:setTouchEnabled(false)   
    ]]
    print("begin")
end

function onTestButton(node)
  print("onTestButton")
end

function onHttpCompleted(data)
  print("onHttpCompleted", data)
  local res = cjson.decode(data)
  for k,v in pairs(res) do
    print(k,v)
  end 
  print("onHttpCompleted",os.time(),res.serverTime,os.time()-res.serverTime)
  DeltaTime = res.serverTime - os.time()
end

xpcall(main, __G__TRACKBACK__)
